home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
1035
/
1035.xpi
/
chrome
/
1clickweather.jar
/
content
/
1clickweather
/
js
/
trackingsystem.js
< prev
Wrap
Text File
|
2009-12-30
|
4KB
|
162 lines
/* 2007 The Weather Channel Interactive, Inc. All Rights Reserved.
*
* This is the tracking system javascript file
*
*/
function weather_trackingSystem(){
/*
* product_id
*
* Identify the service
*/
this.product_id = 17;
/* action_id
*
* Valid values are:
* - 1 for First Time Logging Tag (FTL tag).
* - 2 Daily Active User tag. Throwing every 24 hours (it is throw at startup also).
* - 4 Disable (unninstall) toolbar extension
*/
this.action_id = 0;
/*
* rnd
* This is the caching busting parameter
*
*/
this.rnd = 0;
/*
* uniqueUserIdUrl
*
* This is the url when the service get the unique user id
*/
this.uniqueUserIdUrl = "https://auth.weather.com/weather/installid/";
/*
* tracking url
*/
this.trackingUrl = "http://x.imwx.com/";
/*
* getUniqueUserId()
*
* This method get the unique user id for this user.
*/
this.getUniqueUserId = function(){
var req = new XMLHttpRequest();
req.open('GET', this.uniqueUserIdUrl, true);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200){
// get node
var node = req.responseXML.getElementsByTagName("id")[0].childNodes;
// save user id
GlobalUserConfig.getInfo().setUserId(node[0].nodeValue);
GlobalUserConfig.save();
//alert("[DEBUG]-unique user id from getUniqueUserId:" + GlobalUserConfig.getInfo().getUserId());
}
}
};
req.send(null);
}
/*
* calculateRandomNumber
*/
this.calculateRandomNumber = function(){
return Math.floor(Math.random()*100000000);
}
/*
* sendAnalyticusTag
* action_id params must be: 1,2 or 4
* 0: FTL
* 1: (First Time Logging)
* 2: Daily Active User Tag
* 4: Disable Toolbar Extension (if you see uninstall procedure, see UninstallObserver into the 1clickweather.js file)
*/
this.sendAnalyticusTag = function(action_id){
//alert("action_id is " + action_id);
var req = new XMLHttpRequest();
// testing purpose
//req.onreadystatechange = "if(this.readyState==4 && this.status ==200){alert('sendAnalyticusTags reached');}";
// prepare tracking call
this.trackingCall = this.trackingUrl + this.product_id + "/" + action_id + "?id=" + GlobalUserConfig.getInfo().getUserId() + "&rnd=" + this.calculateRandomNumber();
//alert("I will call to " + this.trackingCall);
req.open('GET', this.trackingCall, false);
req.send(null);
// save last daily update tracking
if(action_id==2){
var d = new Date();
GlobalUserConfig.getInfo().setLastDUT(d.getTime());
GlobalUserConfig.save();
//alert("configuration saved");
}
}
// This method check if daily update tracking is needed.
// Get last daily update tracking from user config and
// compare with the actual date.
// If is neccesary, call to sendAnalyticusTag(2) to update
// track.
this.DailyUpdateTracking = function(){
// get last date tracking from configuration file
var original = new Date();
original.setTime(GlobalUserConfig.getInfo().getLastDUT());
// prepare next update time
var nextDate = new Date();
// nextDate.setFullYear(original.getFullYear(), original.getMonth(),original.getDate());
nextDate.setTime(nextDate.getTime());
if(Math.ceil((nextDate.getTime() - original.getTime())/(24*60*60*1000)) > 1) // update
{
// alert("update DUT");
var track= new weather_trackingSystem();
track.sendAnalyticusTag(2); // Daily user tracking
}
}
// This function call to 17/1 tag. Implement a flag to permit
this.DataPullTracking = function(){
if(weather_trackingSystem.dataPullTrackingFlag == true){
this.sendAnalyticusTag(1);
weather_trackingSystem.dataPullTrackingFlag = false;
setTimeout(setDataPullTrackingFlag, 6000);
}
}
} // End Off Tracking System class
function setDataPullTrackingFlag(){
weather_trackingSystem.dataPullTrackingFlag = true;
}
// Static member
weather_trackingSystem.dataPullTrackingFlag = true;